// 爬虫 数据分析 pythonweb
const http = require('http')
const https = require('https')
const cheerio = require('cheerio')

let movies = []
function filterData(data) {
  const $ = cheerio.load(data)
  let $movieList = $('.section-comment-box .index-center-wrapper ul li')
  $movieList.each((index, value) => {
    movies.push({
      title: $(value).find('.goods-img').attr('data-src'),
      score: $(value).find('p').text(),
    })
  })
}

http.createServer((req, res) => {
  let data = ''
  https.get('https://www.meizu.com', (result) => {
    result.on('data', (chunk) => {
      data += chunk
    })
    result.on('end', () => {
      filterData(data)
    })
  })
  res.end(JSON.stringify(movies))
}).listen('8080', () => {
  console.log('http://localhost:8080')
})